﻿package game.ui {
	import game.objects.GameObject;
	import flash.display.BitmapData;
	import game.objects.FiltersObject;
	
	public class Money extends GameObject {
		
		public static const RIGHT:String	= "value.right";
		public static const LEFT:String		= "value.left";
		
		public static const DONAT:String	= "type.donat";
		public static const MONEY:String	= "type.money";
		
		private var _align:String	= RIGHT;
		private var _type:String	= MONEY;
		private var _value:Number	= 0;
		
		private var image:Image;
		private var text:Text;
		
		public function Money(_type:String, _value:Number = 0, _align:String = null):void {
			if (_type) this._type = _type;
			if (_align) this._align = _align;
			
			var bitmap:BitmapData = (_type==DONAT) ? new DonatImage : new MoneyImage;
			image = new Image(bitmap, bitmap.width, bitmap.height);
			addChild(image);
			
			text = new Text;
			text.setFormat("color", 0xffffff);
			addChild(text);
			
			value = _value;
			
			image.filters = FiltersObject.MONEY;
			
			this.mouseChildren = false;
			this.name = this._type;
		}
		
		public function set value(_value:Number):void {
			this._value = _value;
			
			text.set(String(_value), null, false);
			text.y = (image.height - text.height)/2;
			if (_align==RIGHT) {
				image.x = 0;
				text.x = image.width + 5;
			} else if (_align==LEFT) {
				text.x = 0;
				image.x = text.width + 5;
			}
			
		}
		
		public function get value():Number {
			return _value;
		}
		
	}
	
}